import 'package:flutter/material.dart';
import 'package:module/wallet_page.dart';

import 'const.dart';

class ChongZhiPage extends StatefulWidget {
  const ChongZhiPage({super.key});

  @override
  State<ChongZhiPage> createState() => _ChongZhiPageState();
}

class _ChongZhiPageState extends State<ChongZhiPage> {
  final _Controller = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        backgroundColor: Colors.white,
        centerTitle: true,
        title: Text(
          '账户充值',
          style: TextStyle(color: Colors.black),
        ),
        leading: GestureDetector(
          onTap: () {
            // Navigator.of(context).pop();
            Navigator.push(context, MaterialPageRoute(builder: (context) {
              return WalletPage();
            }));
          },
          child: Transform.scale(
            scale: 0.5,
            child: Image.asset(
              'assets/icon_back.png',
            ),
          ),
        ),
      ),
      body: SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: 20),
          color: Constants.bgColor,
          child: Column(
            children: [
              Container(
                  padding: EdgeInsets.symmetric(
                    vertical: 10,
                  ),
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '选择充值金额',
                    style: TextStyle(color: Colors.grey),
                  )),
              Container(
                height: 170,
                padding: EdgeInsets.symmetric(horizontal: 40, vertical: 30),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(20),
                    color: Colors.white),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        yuanItem('50'),
                        yuanItem('100'),
                        yuanItem('200')
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        yuanItem('500'),
                        yuanItem('1000'),
                        yuanItem('1500')
                      ],
                    ),
                  ],
                ),
              ),
              Container(
                  padding: EdgeInsets.symmetric(
                    vertical: 10,
                  ),
                  alignment: Alignment.centerLeft,
                  child: Text('输入充值金额', style: TextStyle(color: Colors.grey))),
              Container(
                height: 60,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(20),
                    color: Colors.white),
                child: Row(
                  children: [
                    const Padding(
                      padding: EdgeInsets.symmetric(horizontal: 10),
                      child: Text('￥'),
                    ),
                    Expanded(
                        child: TextField(
                      controller: _Controller,
                      decoration: const InputDecoration(
                        border: InputBorder.none,
                        hintText: '请输入你想要充值的金额',
                      ),
                    ))
                  ],
                ),
              ),
              SizedBox(
                height: 100,
              ),
              GestureDetector(
                onTap: () {
                  if (_Controller.text != '') {
                    money += double.parse(_Controller.text);
                    money1 += double.parse(_Controller.text);
                    cz.add(double.parse(_Controller.text));
                    ye.add(money1);
                    print(money);
                    print('cc');
                  } else {
                    print('123');
                  }
                },
                child: Container(
                  height: 50,
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(100),
                      color: _Controller.text == ''
                          ? Colors.grey
                          : Color(0xFFF98B31)),
                  child: Center(
                    child: Text(
                      '确认',
                      style: TextStyle(color: Colors.white, fontSize: 20),
                    ),
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }

  GestureDetector yuanItem(
    String yuan,
  ) {
    return GestureDetector(
      onTap: () {
        setState(() {
          _Controller.text = yuan;
        });
      },
      child: Container(
        width: 80,
        height: 40,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(5),
            border: Border.all(width: 1, color: Colors.grey)),
        child: Center(child: Text('$yuan元')),
      ),
    );
  }
}
